/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package server;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;

/**
 *
 * @author Tri
 */
public class Server {

    /**
     * @param args the command line arguments
     */
    public final static int daytimePort = 5000;

    public static void main(String[] args) {
        // TODO code application logic here
        ServerSocket theServer;
        Socket theConnection;
        PrintStream p;
        try {
            theServer = new ServerSocket(daytimePort);
            while (true) {
                theConnection = theServer.accept();
                System.out.println("Connected");
//                p = new PrintStream(theConnection.getOutputStream());
//                p.println(new Date());
                String clientSentence;
                String capitalizedSentence;
                BufferedReader inFormClient = new BufferedReader(
                        new InputStreamReader(theConnection.getInputStream()));
                DataOutputStream outToServer = new DataOutputStream(theConnection.getOutputStream());
                clientSentence = inFormClient.readLine();
                System.out.println("Sent form client : " + clientSentence);
                capitalizedSentence = clientSentence.toUpperCase()+'\n';
                outToServer.writeBytes(capitalizedSentence);
                System.out.println("Sent to client ");
            }
        } catch (IOException e) {
            System.err.println(e);
        }
    }
}
